$(document).ready(function(){
$('#selectedgal').append('<option selected>pasirinkite</option>'); //default nastroiki
$('#deletegalerija').append('<option selected>pasirinkite</option>'); //default nastroiki
$('#selectedgal2').append('<option selected>pasirinkite</option>'); //default nastroiki

$.post("ajax/select.php", function(data){
$('#deletegalerija').append(data);
}); //end zagruzka delete dropik

$.post("ajax/select.php", function(data){
$('#selectedgal').append(data);
}); //end zagruzka delete dropik

$.post("ajax/select0.php", function(data){
$('#selectedgal2').append(data);
}); //end zagruzka delete dropik

//zagruzka dannix vdelete dropik
$('#newgal').fadeOut(0);
$('#newgal').fadeIn(5000);

$('#newgal').focusout(function(){
var kint=$(this).val();
if(kint==''){
}else{
$.post("ajax/insert.php",{kint:$(this).val()});
alert('Sukurta galerija:'+$(this).val());

$.post("ajax/select.php", function(data){
$('#deletegalerija').empty();
$('#deletegalerija').append('<option selected>pasirinkite</option>');
$('#deletegalerija').append(data);
}); //end zagruzka delete dropik

$.post("ajax/select.php", function(data){
$('#selectedgal').empty();
$('#selectedgal').append('<option selected>pasirinkite</option>');
$('#selectedgal').append(data);
}); //end zagruzka delete dropik

$.post("ajax/select0.php", function(data){
$('#selectedgal2').empty();
$('#selectedgal2').append('<option selected>pasirinkite</option>');
$('#selectedgal2').append(data);
}); //end zagruzka delete dropik
$(this).val('');
}
});
//pasirinkta galerija
$('#selectedgal2').change(function(){
$('#gallery').css('visibility','visible');
$('#sgs').submit();
});

//delete dropika load
$('#deletegalerija').change(function(){
alert('Naikiname:'+$(this).val());
$.post("ajax/delete.php",{kint:$(this).val()});
alert('Panaikinta');

//refresh dropa posle deleta
$.post("ajax/select.php", function(data){
$('#deletegalerija').empty();
$('#deletegalerija').append('<option selected>pasirinkite</option>');
$('#deletegalerija').append(data);
$('#gallery').remove();
$('#galname').text('');
//location.reload();

});
$.post("ajax/select.php", function(data){
$('#selectedgal').empty();
$('#selectedgal').append('<option selected>pasirinkite</option>');
$('#selectedgal').append(data);
});


$.post("ajax/select0.php", function(data){
$('#selectedgal2').empty();
$('#selectedgal2').append('<option selected>pasirinkite</option>');
$('#selectedgal2').append(data);
});


});
//uploader ajaxer
$('#uplsender').click(function(){
if($('#selectedgal').val()!='pasirinkite'){
$('#uplsender').append("<input type='hidden' name='gall' value="+$('#selectedgal').val()); //znat k kakoi galerei fotku
$('#uplsender').append("<input type='hidden' name='nazvanie' value="+$('#selectedgal option:selected').text()); //znat k kakoi galerei fotku
$('#uploaderok').submit();
alert('submit nusiustas');
} //if endas
else
{
alert("Pasirinkite galerija");	
}
});

//delete iz galerii
$("a").filter(".clicker").click(function(){
$(this).closest('li').remove();
$.post("ajax/deleteimage.php",{imgdel:$(this).attr('title')});
 })

});